package org.jeecg.modules.sistersophie.util;
import com.itextpdf.text.Font;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.tool.xml.XMLWorkerFontProvider;
import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.config.StaticConfig;
import org.springframework.core.io.DefaultResourceLoader;

import java.io.File;

public class AsianFontProvider extends XMLWorkerFontProvider{

    @Override
    public Font getFont(String fontname, String encoding, float size, final int style) {
        try {
            StaticConfig staticConfig = SpringContextUtils.getBean(StaticConfig.class);
            String fontPath = staticConfig.getFileFont();
            File file = new DefaultResourceLoader().getResource("").getFile();
            //字体文件绝对路径
             BaseFont bfChinese =BaseFont.createFont( fontPath , BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
            return new Font(bfChinese, size, style);
        } catch (Exception e) {

        }
        return super.getFont(fontname, encoding, size, style);
    }

}
